package com.stormragetech.arthas.common.exception;

import lombok.extern.log4j.Log4j2;

/**
 * description: //TODO
 *
 * @author: Xue Bin
 * @version: 1.0.0-SNAPSHOT
 */
@Log4j2
public class ArthasException extends Exception {

    public final static int SYS_ERR = 0;
    public final static int APP_ERR = 1;

    private String code;
    private String message;
    private int level = APP_ERR;
    private Throwable cause;

    private ArthasException() {
        super();
    }

    public ArthasException(String code, String message, int level) {
        super(message);
        this.code = code;
        this.message = message;
        this.level = level;
    }

    public ArthasException(String code, String message, int level, Throwable cause) {
        super(message);
        this.code = code;
        this.message = message;
        this.level = level;
        this.cause = cause;

    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public void setCause(Throwable cause) {
        this.cause = cause;
    }

    @Override
    public String toString() {
        return "ArthasException{" +
                "code='" + code + '\'' +
                ", message='" + message + '\'' +
                ", level=" + (SYS_ERR == level ? "SYS" : "APP") +
                ((SYS_ERR == level) ? (", cause=" + cause) : "") +
                '}';
    }

}
